package com.winshare.saleAssistant.controller;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.winshare.saleAssistant.config.WxMaConfiguration;
import com.winshare.saleAssistant.domain.dto.req.WxGetOpenIdByCodeDTO;
import com.winshare.saleAssistant.domain.dto.resp.WxOpenIdAndTokenDTO;
import com.winshare.saleAssistant.domain.entity.StaffDO;
import com.winshare.saleAssistant.exception.BusinessException;
import com.winshare.saleAssistant.service.JXZYZXService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

@Controller
@RequestMapping("/apiTest")
public class UserDataController {

    @Resource
    JXZYZXService jxzyzxService;

    @PostMapping("/queryUser")
    public Object queryUser() {
        jxzyzxService.queryUser();
        return LogicResponse.success("success");
    }

    @PostMapping("/queryModules")
    public Object queryModules() {
        jxzyzxService.queryModules();
        return LogicResponse.success("success");
    }

    @PostMapping("/queryUseOperationLogs")
    public Object queryUseOperationLogs() {
        LocalDateTime yd = LocalDateTime.now().plusDays(-1);
        LocalDateTime bgTime = LocalDateTime.of(yd.toLocalDate(), LocalTime.MIN);
        LocalDateTime edTime = LocalDateTime.of(yd.toLocalDate(), LocalTime.MAX);
        String beginDate = bgTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String endDate = edTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        jxzyzxService.queryUseOperationLogs(beginDate, endDate);
        return LogicResponse.success("success");
    }

    @PostMapping("/queryLoginLogs")
    public Object queryLoginLogs() {
        LocalDateTime yd = LocalDateTime.now().plusDays(-1);
        LocalDateTime bgTime = LocalDateTime.of(yd.toLocalDate(), LocalTime.MIN);
        LocalDateTime edTime = LocalDateTime.of(yd.toLocalDate(), LocalTime.MAX);
        String beginDate = bgTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String endDate = edTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        jxzyzxService.queryLoginLogs(beginDate, endDate);
        return LogicResponse.success("success");
    }
}
